package com.xjtu.project.controller.admin;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xjtu.project.common.utls.JsonResponse;
import com.xjtu.project.model.domain.Orders;
import com.xjtu.project.model.dto.OrderRejectionDTO;
import com.xjtu.project.model.dto.OrdersPageQueryDTO;
import com.xjtu.project.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/admin/order")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;
    @PutMapping("cancel")
    public JsonResponse<String> cancel(@RequestBody OrderRejectionDTO orderRejectionDTO){
         ordersService.cancel(orderRejectionDTO);
         return JsonResponse.success(null);
    }
    @PutMapping("/complete/{id}")
    public JsonResponse<String> complete(@PathVariable Integer id){
        ordersService.complete(id);
        return JsonResponse.success(null);
    }
    @GetMapping("details/{id}")
    public JsonResponse<Orders> getById(@PathVariable Integer id){
        Orders orders = ordersService.getById(id);
        return JsonResponse.success(orders);
    }
    @GetMapping("conditionSearch")
    public JsonResponse<Page<Orders>> conditionSearch(OrdersPageQueryDTO ordersPageQuery){
        return JsonResponse.success(ordersService.conditionSearch(ordersPageQuery));
    }

}
